package com.pubinfo.passbook.data.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pubinfo.passbook.common.entity.TFtpPassword;
import com.pubinfo.passbook.common.mapper.TFtpPasswordMapper;
import com.pubinfo.passbook.common.model.constant.RedisKey;
import com.pubinfo.passbook.common.service.cache.JedisManage;
import com.pubinfo.passbook.data.service.TFtpPasswordService;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xuhong
 * @since 2022-04-01
 */
@Service
public class TFtpPasswordServiceImpl extends ServiceImpl<TFtpPasswordMapper, TFtpPassword> implements TFtpPasswordService {

    @Resource
    JedisManage jedis;

    @Override
    public String getPassword() {
        if(StringUtils.isEmpty(jedis.getStr(RedisKey.FTP_PASSWORD)))
        {
            String password=this.baseMapper.getPassword();
            jedis.putStr(RedisKey.FTP_PASSWORD,password);
        }
        return jedis.getStr(RedisKey.FTP_PASSWORD);
    }

    @Override
    public Boolean updatePassword(String password) {
        TFtpPassword tFtpPassword=new TFtpPassword(password);
        if(this.baseMapper.insert(tFtpPassword)==1)
        {
            jedis.putStr(RedisKey.FTP_PASSWORD,password);
            return true;
        }
        return false;
    }


}
